<template>
  <el-submenu v-if="menu.children && menu.children.length > 0" :key="menu.permId" :index="'' + menu.permId">
    <template slot="title">
      <i :class="menu.icon"></i>
      <span slot="title">{{menu.description}}</span>
    </template>
    <perm-tree v-for="item in menu.children" :key="item.permId" :menu="item"></perm-tree>
  </el-submenu>
  <el-menu-item v-else :index="'' + menu.permId" @click="handleRoute(menu)">
    <i :class="menu.icon"></i>
    <span slot="title">{{menu.description}}</span>
  </el-menu-item>
</template>

<script>
export default {
    name: 'PermTree',
    props: {
        menu: {
            type: Object,
            require: true
        }
    },
    methods: {
        handleRoute: function(menu) {
            if (menu.permId) {
                // 通过菜单URL跳转至指定路由
                this.$router.push(menu.permUrl)
            } else {
                // 跳转到首页
                this.$router.push(this.global.homeUrl)
            }
        }
    }
}
</script>
<style scoped>
</style>
